package net.pws.common.security;

import net.pws.common.security.spi.Principal;

import org.springframework.util.Assert;


public class SecurityContext {
    
    private static ThreadLocal<String> tokenHolder = new ThreadLocal<String>();
    
    private static ThreadLocal<Principal> contextHolder = new ThreadLocal<Principal>();
    
    public static void clear() {
        tokenHolder.set(null);
        contextHolder.set(null);
    }
    
    public static String getToken() {
        return tokenHolder.get();
    }
    
    public static Principal getContext() {
        return contextHolder.get();
    }
    
    public static void setToken(String token) {
        Assert.notNull(token, "Only non-null String instances are permitted");
        tokenHolder.set(token);
    }
    
    public static void setContext(Principal principal) {
        Assert.notNull(principal,
                       "Only non-null Principal instances are permitted");
        contextHolder.set(principal);
    }
    
}
